package cn.wolfcode.crud.service.impl;

import cn.wolfcode.crud.domain.Role;
import cn.wolfcode.crud.mapper.RoleMapper;
import cn.wolfcode.crud.qo.QuerObjcet;
import cn.wolfcode.crud.service.IRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public void delete(Long id) {
        roleMapper.deleteRp(id);
        roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Role role, Long[] ids) {

        roleMapper.insert(role);
        if (ids !=null && ids.length>0){
            roleMapper.save(role.getId(),ids);
        }
    }

    @Override
    public Role get(Long id) {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Role> selectAll() {
        return roleMapper.selectAll();
    }

    @Override
    public void update(Role role, Long[] ids) {
        roleMapper.deleteRp(role.getId());
        roleMapper.updateByPrimaryKey(role);
        if (ids !=null && ids.length>0){
            roleMapper.save(role.getId(),ids);
        }

    }
    //封装页面信息
    @Override
    public PageInfo<Role> query(QuerObjcet qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Role> formList = roleMapper.queryFormList(qo);
        return new PageInfo<Role>(formList);
    }
}
